package com.mingqijia.gassafety.job.job.asst;

import com.mingqijia.gassafety.job.service.WorkOrderHistoryService;
import com.mingqijia.gassafety.shared.constant.Constants;
import com.mingqijia.gassafety.shared.utils.RedisCacheExt;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @author zhangfei
 * @version 1.0.0
 * @ClassName EquipmentAepJob.java
 * @Description 设备数据同步
 * @createTime 2022年5月10日
 */
@Configuration
@EnableScheduling
@Slf4j
public class AsstOrderJob {

    @Autowired
    RedisCacheExt redisUtil;
    @Autowired
    WorkOrderHistoryService workOrderHistoryService;

    /**
     * 查询工单状态    0 0/30 * * * ?
     */
    @Scheduled(cron = "${gassafety.job.asst.order.status}")
    public void getOrderStatus() {
        log.info("getOrderStatus--start--------");
        String key = Constants.ASST_ORDER_STATUS;
        Boolean acquire = redisUtil.setIfAbsent(key, String.valueOf(System.currentTimeMillis()), Constants.TIME_OUT);//15分钟超时
        if (acquire) {
            try {
                workOrderHistoryService.updateHandleStatusByOrderNo();
            } catch (Exception e) {
                log.info("getOrderStatus-error:{}", e);
            } finally {
                redisUtil.del(key);
            }
        } else {
            log.info("getOrderStatus jog 加锁失败，不处理");
            return;
        }
        log.info("getOrderStatus--end--------");
    }
}
